package com.ethan.modules.organization.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ethan.common.orm.Page;
import com.ethan.modules.organization.model.User;
import com.ethan.modules.organization.service.UserService;

@Controller
@RequestMapping("/userAction")
public class UserAction {
	@Resource
	private UserService userService;
	
	@RequestMapping(value = "/userList", method = RequestMethod.GET)
	public ModelAndView list(String pageNo, String id) {
		ModelAndView mv = new ModelAndView();
		Page<User> page = new Page<User>(10);

		page.setPageNo(pageNo == null ? 1 : Integer.valueOf(pageNo).intValue());

		// 设置默认排序方式
		if (!page.isOrderBySetted()) {
			page.setOrderBy("id");
			page.setOrder(Page.ASC);
		}

		String hql = "from User where id = " + id + "";
		User user = userService.findID(Long.parseLong(id));
		mv.addObject("page", userService.findPage(page, hql));
		mv.addObject("user", user);
		mv.setViewName("org/userlist");
		return mv;
	}
	
	public ModelAndView save(User user){
		ModelAndView mv = new ModelAndView();
		
		return mv;
	}
}
